<?php
/**
 * Created by PhpStorm.
 * User: GMC02
 * Date: 12/4/13
 * Time: 11:31 AM
 */

class PrettyActiveRecord extends CActiveRecord {
    private static $dbPretty = null;

    protected static function getPrettyDbConnection() {
        if (self::$dbPretty !== null)
            return self::$dbPretty;
        else {
            self::$dbPretty = Yii::app()->prettytre_db;
            if (self::$dbPretty instanceof CDbConnection) {
                self::$dbPretty->setActive(true);
                return self::$dbPretty;
            } else
                throw new CDbException(Yii::t('yii',
                    'Active Record requires a "db" CDbConnection application component.'));
        }
    }

    public function getDbConnection() {
        return self::getPrettyDbConnection();
    }
} 